import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Random;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;


public class MyFrame extends JFrame implements ActionListener {
	
	private JTextArea numberArea;
	private JTextArea wordArea;
	
	public MyFrame() {
		super("My Frame");
		setSize(400, 300);
		
		JPanel textPanel = new JPanel();
		JPanel buttonPanel = new JPanel();
		
		setLayout(new BorderLayout());
		Container c = getContentPane();
		c.add(textPanel, BorderLayout.NORTH);
		c.add(buttonPanel, BorderLayout.SOUTH);
		
		numberArea = new JTextArea();
		numberArea.setColumns(40);
		numberArea.setRows(30);
		wordArea = new JTextArea();
		wordArea.setColumns(40);
		wordArea.setRows(30);
		
		textPanel.setLayout(new FlowLayout());
		textPanel.add(new JScrollPane(numberArea));
		textPanel.add(new JScrollPane(wordArea));
		
		JButton numberButton = new JButton("Number");
		JButton textButton = new JButton("Text");
		JButton clearButton = new JButton("Clear");
		JButton exitButton = new JButton("Exit");
		
		buttonPanel.setLayout(new FlowLayout());
		buttonPanel.add(numberButton);
		buttonPanel.add(textButton);
		buttonPanel.add(clearButton);
		buttonPanel.add(exitButton);
		
		numberButton.addActionListener(this);
		textButton.addActionListener(this);
		clearButton.addActionListener(this);
		exitButton.addActionListener(this);
		
		setDefaultCloseOperation(EXIT_ON_CLOSE);
	}

	public void actionPerformed(ActionEvent e) {
		if(e.getActionCommand() == "Number") {
			numberAction();
		} else if(e.getActionCommand() == "Text") {
			textAction();
		} else if(e.getActionCommand() == "Clear") {
			clearAction();
		} else if(e.getActionCommand() == "Exit") {
			exitAction();
		}
		
		
	}
	
	private void exitAction() {
		wordArea.setText("Goodbye!!");
		System.exit(0);
	}

	private void textAction() {
		wordArea.setText("This text is read from the file");
		String path = "";
		File file = new File(path);
		try {
			InputStreamReader ir = new InputStreamReader(new FileInputStream(file));
			BufferedReader reader = new BufferedReader(ir);
			String line = reader.readLine();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}

	private void clearAction() {
		numberArea.setText("");
		wordArea.setText("");
	}

	private void numberAction() {
		numberArea.setText("");
		numberArea.setAlignmentX(RIGHT_ALIGNMENT);
		Random random = new Random(0);
		for (int i = 1; i <= 150; i++) {
			int randomInt = random.nextInt(9999);
			if(i % 6 == 0) {
				numberArea.setText(numberArea.getText() + " " + String.valueOf(randomInt) + "\n");
			} else {
				numberArea.setText(numberArea.getText() + String.valueOf(randomInt) + " ");
			}
		}
	}

	public static void main(String[] args) {
		new MyFrame().setVisible(true);
	}
	
	

}
